//
//  PopAnimateDismiss.swift
//  UIViewDemo
//
//  Created by 劢克科技 on 2019/3/8.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class PopAnimateDismiss: PopAnimateBase {
    
}

extension PopAnimateDismiss: UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return dismissTime
    }
    
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        dismissAnimate(transitionContext: transitionContext)
    }
    
    // 隐藏动画
    func dismissAnimate(transitionContext: UIViewControllerContextTransitioning) {
        // 隐藏动画,注意：时长应该统一
        guard let dismissView = transitionContext.view(forKey: .from) else { return }
        transitionContext.containerView.addSubview(dismissView)
        
        dismissView.alpha = 1
        
        UIView.animate(withDuration: dismissTime, animations: {
            dismissView.alpha = 0
        }) { (_) in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
        }
    }
}

// 交互动画

extension PopAnimateDismiss: UIViewControllerInteractiveTransitioning {
    func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) {
//        transitionContext.completeTransition(true)
        transitionContext.finishInteractiveTransition()
        print("123")
    }
    
    
}
